package com;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class _03_UDPServer {

	public static void main(String[] args) throws IOException {
		// 打开 UDP 对象,并监听某个端口,用于数据接收
		DatagramSocket ds = new DatagramSocket(10000);
		// 声明一个数组,存放保存的数据
		byte[] buf = new byte[1024];

		// 包接收器
		DatagramPacket dp = new DatagramPacket(buf, buf.length);

		while (true) {
			// 接受数据
			ds.receive(dp);
			System.out.println(new String(buf));

//			ByteArrayInputStream bais = new ByteArrayInputStream(buf);
//			DataInputStream dis = new DataInputStream(bais);
//			System.out.println(dis.readUTF());
		}
	}

}
